package org.come.control;

import org.come.action.FromServerAction;
import org.come.bean.GetClientUserMesageBean;
import org.come.bean.LoginResult;
import org.come.bean.RoleShow;
import org.come.thread.LoadYeguaiRunnable;
import org.come.until.GsonUtil;
import org.come.until.Util;

import com.tool.image.ImageMixDeal;
import com.tool.image.ManimgAttribute;
import com.tool.role.RoleData;

/**
 * 
 * @author 黄建彬 返回进入游戏 inogam处理方法
 * 
 */
public class IntoGameControl implements FromServerAction {
	@Override
	public void controlMessFromServer(String mes, String type) {
		GetClientUserMesageBean list2 = GsonUtil.getGsonUtil().getgson().fromJson(mes, GetClientUserMesageBean.class);
		if (list2.getIsmap() == 1) {
			try {
				ImageMixDeal.Playerimgmap.clear();
				ImageMixDeal.mapMonsterlist.clear();
				ImageMixDeal.stalls.clear();
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}
		}
		// 进行收到的消息处理
		if (list2.getRoleShows().size() != 0) {
			for (int i = list2.getRoleShows().size() - 1; i >= 0; i--) {
				RoleShow roleShow = list2.getRoleShows().get(i);
				if (roleShow == null) {
					continue;
				}
				ManimgAttribute attribute = ImageMixDeal.huoquLogin(roleShow.getRolename());
				if (attribute == null) {
					ImageMixDeal.Playerimgmap.put(roleShow.getRolename(), new ManimgAttribute(roleShow, 1));
				} else {
					attribute.setRoleShow(roleShow);
					attribute.changeskin(null);
					attribute.CZmove();
					if (attribute.getLeixing() == 0) {
						LoginResult loginResult=RoleData.getRoleData().getLoginResult();
						loginResult.setX((long)roleShow.getX());
						loginResult.setY((long)roleShow.getY());
						loginResult.setMapid(roleShow.getMapid());
						Util.dogame(loginResult);

					}
				}
			}
		}
		// 接收野怪集合
		if (list2.getMonster() != null) {
			LoadYeguaiRunnable loadYeguaiRunnable = new LoadYeguaiRunnable(list2.getMonster());
			Thread t = new Thread(loadYeguaiRunnable);
			t.start();
		}
		if (list2.getStallBeans() != null) {
			for (int i = list2.getStallBeans().size() - 1; i >= 0; i--) {
				ImageMixDeal.stall(list2.getStallBeans().get(i));
			}
		}
		ImageMixDeal.upScene(list2.getSceneMsg());
	}

}
